package edu.hz.controller;

import edu.hz.model.dto.UserLoginDto;
import edu.hz.model.dto.UserRegisterDto;
import edu.hz.service.UserService;
import edu.hz.util.web.ApiResponse;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@CrossOrigin(origins = "*")
@RestController
public class UserController {

    @Resource
    UserService userService;

    @PostMapping("/user/register")
    public ApiResponse<Void> registerUser(@RequestBody UserRegisterDto userRegisterDto) {
        return userService.addUser(userRegisterDto);
    }

    @PostMapping("/user/login")
    public ApiResponse<String> login(@RequestBody UserLoginDto userLoginDto) {
        return userService.login(userLoginDto);
    }

}
